﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace FOBTV.Web.DBUtility
{
	internal class DBHelperFactory
	{
		/// <summary>
		/// 当前使用数据库类型
		/// </summary>
		public const string DB_CURRENT = DB_ACESSS;
		public const string DB_ACESSS = "ACCESS";
		public const string DB_SQLSERVER = "SQLSERVER";
		private static IDBHelper iDBHelper;
		private static IDataParameter iParameter;
		private DBHelperFactory() { }
		/// <summary>
		/// 通过传入的数据库类型生成相应的数据库帮助类
		/// </summary>
		/// <param name="dataBaseName"></param>
		/// <returns></returns>
		public static IDBHelper CreateInstance(string dataBaseName)
		{
			switch (dataBaseName)
			{
				case DB_SQLSERVER:
					iDBHelper = new OleSqlHelper();
					break;
				case DB_ACESSS:
					iDBHelper = new OleSqlHelper();
					break;
			}
			return iDBHelper;
		}
		/// <summary>
		/// 通过数据库名称生成Parameter类
		/// </summary>
		/// <param name="dataBaseName"></param>
		/// <returns></returns>
		public static IDataParameter CreateParameter(string dataBaseName, PropertyAttribute attr)
		{
			switch (dataBaseName)
			{
				case DB_SQLSERVER:
					iParameter = new SqlParameter("@" + attr.ColumnName, attr.DbType);
					break;
				case DB_ACESSS:
					iParameter = new OleDbParameter("@" + attr.ColumnName, attr.DbType);
					break;
			}
			return iParameter;
		}
	}
}